package pri.hillchen.springbootstd.sso.common.response;

import pri.hillchen.springbootstd.sso.common.page.PageInfo;
import pri.hillchen.springbootstd.sso.common.page.PageRecode;

import java.util.List;

/**
 * @author:hillchen
 * @DESCRIPTION:
 * @Date: Created in 9:17 2017/12/26 0026.
 */
public class PageResponse<T> extends BaseResponse<PageRecode<T>> {
    public PageResponse() {
        this(new PageInfo());
    }
    public PageResponse(PageInfo pageInfo) {
        setReqResult(new PageRecode<>(pageInfo));
    }

    private PageRecode<T> getOrInitPageRecode(){
        PageRecode<T> pageRecode = getReqResult();
        if(pageRecode == null){
            pageRecode = new PageRecode<>();
            setReqResult(pageRecode);
        }
        return pageRecode;
    }
    public void setTotal(long total){
        PageRecode<T> pageRecode = getOrInitPageRecode();
        pageRecode.setTotal(total);
    }

    public void setRecodes(List<T> recodes){
        getOrInitPageRecode().setPageRecodes(recodes);
    }
}
